#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int count1 = n / 8 + 1;
    int count2 = 0;
    int sum = count1 * 8 + count2 * 6;
    while (sum != n && count1 >= 0)
    {
        count1--;
        count2++;
        sum = count1 * 8 + count2 * 6;
    }
    if (sum == n)
        cout << (count1 + count2);
    else
        cout << -1;
    return 0;
}